package com.zmzncs.lmtc.module.shop.pojo.shop_goods;

import com.zmzncs.lmtc.common.util.ExceptionUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 商户-商品
 * </p>
 *
 * @author 高博文
 * @since 2021-05-20
 */
@Data
public class GoodsAddForm implements Serializable {

    private static final long serialVersionUID=1L;

    @ApiModelProperty(value = "商户id",required = true)
    @NotNull
    private Long shopId;

    @ApiModelProperty(value = "商品名称",required = true)
    @NotNull
    @Size(max = 15)
    private String goodsName;

    @ApiModelProperty(value = "价格",required = true)
    @NotNull
    @Max(value = 100000)
    private BigDecimal originalPrice;

    @ApiModelProperty(value = "销售价",required = true)
    @NotNull
    @Max(value = 100000)
    private BigDecimal sellPrice;

    @ApiModelProperty(value = "库存",required = true)
    @NotNull
    @Max(value = 2147483647)
    private Integer stock;

    @ApiModelProperty(value = "商品图片",required = true)
    @NotNull
    private List<String> imageList;

    @ApiModelProperty(value = "是否限购（0：否，1：是）",required = true)
    @NotNull
    private Integer isLimitQuantity;

    @ApiModelProperty(value = "限购数量",required = true)
    @Max(value = 2147483647)
    private Integer limitQuantity;

//    @ApiModelProperty(value = "是否永久（0：否，1：是）",required = true)
//    @NotNull
//    private Integer isPermanent;
//
//    @ApiModelProperty(value = "有效期天数",required = true)
//    @Max(value = 2147483647)
//    private Integer expireDate;

    @ApiModelProperty(value = "商品描述",required = true)
    @NotNull
    @Size(max = 63)
    private String description;

    public void validate(){

        //判断限购数量
        if (isLimitQuantity.equals(1) && limitQuantity == null) {
            ExceptionUtil.paramException("限购，限购数量不能为空");
        }

//        //判断有效期天数
//        if ("0".equals(isPermanent) && expireDate == null){
//            ExceptionUtil.paramException("非永久，有效期天数不能为空");
//        }

    }

}
